#ifndef _SEU_TDISKIO_H_
#define _SEU_TDISKIO_H_
#include"include.h"

typedef struct {
   filemanage_t *fmanage;
   cookiemanage_t *cmanage;
   dict_t *readSession;
} tdisk_t;

typedef struct {
   tdisk_t *manager; // Torrent disk io manager to use
   list_t *filelist; // Ordered list of sfiles in the torrent
   char *baseDir;    // Base directory of torrent files for this torrent

   int index;        // Torrent-based index of data to read/write
   int piecelen;     // Length of each piece of the torrent
   int offset;       // Offset within the particular piece to read/write from
   unsigned int datalen; // Total length of data to read/write
} tdiskop_t;

tdisk_t *tdiskInit();
void tdiskRun(tdisk_t *);

/* Ends all critical processes, cleans up memory used by the tdisk_t, and frees
 * the tdisk_t itself. One should join() the thread that the tdisk is running
 * on after this.
 */
void tdiskExitAndCleanup(tdisk_t *);

/* Writes segments of data from disk specified by the notation used by the
 * torrent protocol.
 */
void tdisk_writeData(tdiskop_t opdata, void *data);

/* Reads segments of data from disk specified by the notation used by the
 * torrent protocol. After attempting to read the data, the callback is called,
 * which should be specified as:
 * void func(peer_t *peer, void *data, int error)
 */
void tdisk_readData(tdiskop_t opdata, peer_t *p,
      void (*callback) (peer_t *, void *, int));

tdisk_t *diskman;
#endif
